package com.haitaoit.chengquan.ui.invitation.request;

import com.github.retrofitutil.NetWorkManager;
import com.haitaoit.chengquan.base.MyCallBack;
import com.haitaoit.chengquan.ui.equipment.response.ResponseItem;
import com.haitaoit.chengquan.ui.invitation.request.bean.InvitationCommitBean;
import com.haitaoit.chengquan.ui.invitation.response.InvitationBean;
import com.haitaoit.chengquan.ui.invitation.response.InvitationTypeBean;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2017/5/17.
 */

public class ApiRequest {
    private static Retrofit getClient(){
        return NetWorkManager.getGeneralClient();
    }
    private static Retrofit getSimpleClient(){
        return NetWorkManager.getSimpleClient();
    }
    private static Retrofit getSimpleUpdateURLClient(String url){
        return NetWorkManager.getSimpleUpdateBaseUrlClient(url);
    }
    public static void getInvitationData(Map<String, String> map, final Callback<InvitationBean> callBack){
        Call<InvitationBean> call = getClient()
                .create(IRequest.class)
                .getInvitationData(map);
        call.enqueue(callBack);//异步请求
    }
    public static void getInvitationType(String rnd,String sign, final Callback<InvitationTypeBean> callBack){
        Call<InvitationTypeBean> call = getClient()
                .create(IRequest.class)
                .getInvitationType(rnd,sign);
        call.enqueue(callBack);//异步请求
    }

    public static InputStream getImg2( ){
        /*ResponseBody  img =   getSimpleClient().create(IRequest.class).getImg();
        InputStream is = img.byteStream();
        return is;*/
        return null;
    }
    public static InputStream getImg(String baseUrl,String url){
        Call<ResponseBody> img = NetWorkManager.getSimpleUpdateBaseUrlClient(baseUrl).create(IRequest.class).getImg(url);
        try {
            Response<ResponseBody> responseBody=img.execute();
            InputStream is = responseBody.body().byteStream();
            return is;
        } catch (IOException e) {
            return null;
        }
    }
    public static void commitTieZi(String id, String userId, String sign, InvitationCommitBean bean, MyCallBack<ResponseItem> callBack){
        Call<ResponseItem> call = getClient().create(IRequest.class).commitTieZi(id,userId,sign,bean);
        call.enqueue(callBack);
    }
}
